000100 IDENTIFICATION DIVISION.
000200 PROGRAM-ID. DATABASECONNECTION.
       AUTHOR. GROEP 28.
       AUTHOR. MICHEL GRYP.
       AUTHOR. MICHAEL HEUGHEBAERT.
       AUTHOR. MATTHIAS REYNAERT.

       ENVIRONMENT DIVISION.
               
       DATA DIVISION.
       WORKING-STORAGE SECTION.
       COPY SQLCACOPY. 
       COPY LOGHELPERCOPY.      
 
       LINKAGE SECTION.
       COPY OPENCLOSECOPY.
       01 JDBCSTRING                  PIC X(255).
       
       PROCEDURE DIVISION USING OPENCLOSE, JDBCSTRING. 
       
       PGM. 
       
       MOVE "Database Connection*" TO LOGPROGRAM
       
       IF OPENCONNECTION
         PERFORM STARTUP
       END-IF
       
       IF CLOSECONNECTION
         PERFORM SHUTDOWN
       END-IF

       EXIT PROGRAM.
       
       STARTUP.
       MOVE "Attempting to connect to database" TO LOGMESSAGE
       PERFORM LOGGER
       
       EXEC SQL     
         CONNECT TO :JDBCSTRING
         DRIVER "com.microsoft.sqlserver.jdbc.SQLServerDriver" 
       END-EXEC
       
       IF SQLCODE <> 0
         MOVE SQLERRMC TO LOGMESSAGE
         PERFORM LOGGER
       ELSE
         MOVE "Connected to database" TO LOGMESSAGE
         PERFORM LOGGER
       END-IF
       
       SHUTDOWN.
       EXEC SQL
         COMMIT
       END-EXEC
       
       EXEC SQL
         DISCONNECT 
       END-EXEC
       
       MOVE "Disconnected from database" TO LOGMESSAGE
       PERFORM LOGGER
       
       LOGGER.
       CALL "Logger" USING LOGLINE          